<?php
session_start();

function trim_value(&$value) 
{ 
    $value = trim($value); 
}
foreach ($_POST as $key=>$value){
    foreach($value as $v){
    $clean_data[$key][] = htmlspecialchars($v, ENT_QUOTES, 'UTF-8');
    }
   
}

foreach ($clean_data as $key=>$value){
   array_walk($clean_data[$key], 'trim_value');
   
}

if(empty($_POST['adress1'][0]) || empty($_POST['postcode'][0]) ||
   empty($_POST['city'][0]) || empty($_POST['region'][0])){
    $_SESSION['error'][]="Попълнете задължителните полета ";
    $_SESSION['prev_data_adr']=$clean_data;
   header("Location:../adress.php");
        }else{  
           if(isset($_POST['add'])==true){
               unset($_SESSION['prev_data_adr']);
               $_SESSION['adress'] =$clean_data;
           header("Location:../adress.php");
            }else{
            $_SESSION['adress']=$clean_data;
              unset($_SESSION['prev_data_adr']);
            header("Location:../notes.php");
            }  
  }
        
       